package com.may.wind.controller;

import com.may.wind.entity.Menu;
import com.may.wind.pojo.Result;
import com.may.wind.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 风
 */
@RestController
@Api(tags = "菜单相关API")
public class MenuController {
    @Autowired
    MenuService menuService;

    /**
     * 获取所有菜单信息
     *
     * @return 菜单信息
     */
    @GetMapping("/api/menu/getMenus")
    @ApiOperation(value = "获取所有菜单信息", httpMethod = "GET")
    public Result getMenus() {
        List<Menu> menus = menuService.getMenusByCurrentUser();
        return Result.ok().data("menus", menus);
    }

    /**
     * 依据角色查询菜单信息
     *
     * @param roleId 角色ID
     * @return 菜单信息
     */
    @GetMapping("/api/menu/getMenusByRoleId")
    @ApiOperation(value = "依据角色查询菜单信息", httpMethod = "GET")
    @ApiImplicitParam(name = "roleId", value = "角色ID", required = true)
    public Result getMenusByRoleId(long roleId) {
        List<Menu> menus = menuService.getMenusByRoleId(roleId);
        return Result.ok().data("menus", menus);
    }
}
